﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Telerik.Web.Mvc;
using ProjectManagement.Models;
using Projectmanagement.Utl;
using Projectmanagement.Entity;

namespace Projectmanagement.Controllers
{
    public class ChamberController : Controller
    {

        public ActionResult Index()
        {
            return View();
        }
        [GridAction]
        public ActionResult _SelectIndex(int? conferenceid, string ChamberStructure)
        {
            if (!string.IsNullOrWhiteSpace(ChamberStructure))
            {
                return View(new GridModel(DQ.GetChamber(conferenceid).Where(s => s.ChamberStructure == ChamberStructure)));
            }
            else
            {
                return View(new GridModel(DQ.GetChamber(conferenceid)));
            }
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _SaveAjaxEditing(int id, int? conferenceid)
        {
            var item = CH.GetDataByID<Chamber>(id);
            if (TryUpdateModel(item))
            {
                if (item.Customerid != null)
                {
                    item.Customerid = conferenceid;
                }
                CH.Edit<Chamber>(item);
            }
            return View(new GridModel(DQ.GetChamber(conferenceid)));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _InsertAjaxEditing(int? conferenceid)
        {
            var item = new Chamber();

            if (TryUpdateModel(item))
            {
                item.Customerid = conferenceid;
                CH.Create<Chamber>(item);
            }
            return View(new GridModel(DQ.GetChamber(conferenceid)));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _DeleteAjaxEditing(int id, int? conferenceid)
        {
            CH.Delete<Chamber>(id);
            return View(new GridModel(DQ.GetChamber(conferenceid)));
        }

    }
}
